#pragma once
#include<stdio.h>
#include<stdlib.h>
typedef char TElemType;
typedef struct Node {
	TElemType data;
	struct Node* Lchild, * rsibling;
}CSNode,*CSTree;


void createCSTree_Dagree(CSNode*& t, TElemType e[], int degree[], int n)
{
	if (n == 0)
	{
		t = NULL;
		return;
	}
	int d, k = 1;
	CSTree* Q = (CSTree*)malloc(n*sizeof(CSTree));
	for (int i = 0; i < n; i++)
	{
		Q[i] = (CSTree)malloc(sizeof(CSNode));
		Q[i]->data = e[i];
		Q[i]->Lchild = Q[i]->rsibling = NULL;
	}
	for (int i = 0; i < n; i++)
	{
		int d = degree[i];
		if (d > 0)
		{
			Q[i]->Lchild = Q[k];
			for (int j = 1; j < d; j++)
			{
				Q[k + j - 1]->rsibling = Q[k + j];
			}
			k += d;
		}
	}
	t = Q[0];
	free(Q);
}